<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Middleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class ApiTimeConsumingMiddleware
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $start_time = microtime(true);
        $r = $handler->handle($request);
        $run_time_s = (microtime(true) - $start_time);
        $run_time = (microtime(true) - $start_time) * 1000;
        echo $request->getUri()->getPath() . ' 耗时: ' . $run_time . 'ms---' . $run_time_s . 's' . PHP_EOL;
        return $r;
    }
}
